package woaini.wind.bot.rasa.action;

import cn.hutool.core.util.StrUtil;
import woaini.wind.bot.rasa.base.Action;
import woaini.wind.bot.rasa.base.CollectingDispatcher;
import woaini.wind.bot.rasa.base.domain.Domain;
import woaini.wind.bot.rasa.base.event.Event;
import woaini.wind.bot.rasa.base.exception.RejectExecuteException;
import woaini.wind.bot.rasa.base.message.Message;
import woaini.wind.bot.rasa.base.tracker.Tracker;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import woaini.wind.bot.rasa.utils.DateTool;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 查询时间相关的动作
 *
 * @see QueryDateTimeAction
 * @author yefeng {@date 2024-10-29 17:58:15}
 */
@Component
@Slf4j
public class QueryDateTimeAction implements Action {
  @Override
  public String name() {
    return "action_query_date_time";
  }

  @Override
  public List<? extends Event> run(
      CollectingDispatcher dispatcher, Tracker tracker, Domain domain)
      throws RejectExecuteException {

    String date = tracker.getStringSlot("date_slot");
    String query_date_type_slot = tracker.getStringSlot("query_date_type_slot");

    String message = null;

    log.info("{}->{}",date,query_date_type_slot);
    switch (query_date_type_slot){
      case "query_time"->{

        LocalDateTime now = LocalDateTime.now();
        message = STR."现在是北京时间\{now.getHour()}点\{now.getMinute()}分哦";
      }
      case "query_date"->{
        LocalDate withDay = DateTool.getDateWithDay(date);
        message = STR."\{date}是\{withDay.getMonthValue()}月\{withDay.getDayOfMonth()}号";
      }
      case "query_weekday"->{
        LocalDate withDay = DateTool.getDateWithDay(date);
        message = STR."\{date}是星期\{withDay.getDayOfWeek().getValue()}";
      }
      case null, default ->{}
    }
    if (StrUtil.isNotEmpty(message)){
      dispatcher.utterMessage(Message.builder().text(message).build());
    }
    return List.of();
  }
}
